import axios from "axios";

const baseUrl = "/api";

class HttpRequest {
    constructor(baseUrl) {
        this.baseUrl = baseUrl;
    }
    getInsideConfig() {
        const config = {
            baseURL: this.baseUrl,
            header: {},
        };
        return config;
    }

    interception(instance) {
        instance.interceptors.request.use(
            (config) => {
                // console.log(config);
                return config;
            },
            (error) => {
                console.log(error);
                return Promise.reject(error);
            }
        );

        instance.interceptors.response.use(
            (response) => {
                // console.log(response);
                return response;
            },
            (error) => {
                console.log(error);
                return Promise.reject(error);
            }
        );
    }

    request(options) {
        options = { ...this.getInsideConfig(), ...options };
        const instance = axios.create();
        this.interception(instance);
        return instance(options);
    }
}

export default new HttpRequest(baseUrl);
